package com.yc.cloud.basic.utils;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;
import lombok.val;

import java.util.Map;

public class MyFastJsonUtils {

    public static Map<String, Object> object2Map(Object object) {
        if (object == null) {
            return null;
        }
        val json = JSON.toJSONString(object, SerializerFeature.WriteMapNullValue);
        return JSON.parseObject(json, Map.class);
    }


    public static Object map2Object(Map<Object, Object> map, Class<?> clazz) {
        if (map == null) {
            return null;
        }
        val json = JSON.toJSONString(map, SerializerFeature.WriteMapNullValue);
        return JSON.parseObject(json, clazz);
    }


    public static String object2Str(Object object) {
        if (object == null) {
            return null;
        }
        return JSON.toJSONString(object, SerializerFeature.WriteMapNullValue);
    }


}
